import { Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from "typeorm";
import { EntityModel } from "@midwayjs/orm";
import { Users } from "./Users.entity";
import { RescueInfo } from "./RescueInfo.entity";

@EntityModel("rescue_record", { schema: "heart_neighbor" })
export class RescueRecord {
  @PrimaryGeneratedColumn({ type: "int", name: "id", comment: "Primary Key" })
  id!: number;

  @Column("datetime", {
    name: "create_time",
    nullable: true,
    comment: "Create Time",
    default: () => "CURRENT_TIMESTAMP",
  })
  createTime!: Date | null;

  @Column("int", { name: "user_id", nullable: true, comment: "帮扶者ID" })
  userId!: number | null;

  @Column("int", { name: "item_id", nullable: true, comment: "事项ID" })
  itemId!: number | null;

  // 多对一关系：多个救助记录属于一个用户（帮扶者/救助人）
  @ManyToOne(() => Users, (user) => user.rescueRecords, { createForeignKeyConstraints: false })
  @JoinColumn({ name: "user_id" })
  user!: Users;

  // 多对一关系：多个救助记录对应一个救助信息
  @ManyToOne(() => RescueInfo, (rescueInfo) => rescueInfo.rescueRecords, { createForeignKeyConstraints: false })
  @JoinColumn({ name: "item_id" })
  rescueInfo!: RescueInfo;
}
